//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.ui.mmpac.pmo.pac0002.action;

import nc.bs.framework.common.NCLocator;
import nc.bs.pub.action.listener.IPMOCloseServerIpm;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.itf.pubapp.pub.exception.IResumeException;
import nc.ui.mmpac.pmo.pac0002.serviceproxy.PMOService;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pubapp.pub.task.ISingleBillService;
import nc.util.mmf.framework.base.MMArrayUtil;
import nc.vo.mmpac.pmo.pac0002.constant.PMOConstLang;
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
import nc.vo.mmpac.pmo.pac0002.enumeration.PMOFBillstatusEnum;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.scmpub.exp.AtpNotEnoughException;
import nc.vo.scmpub.res.BusinessCheck;

public class PMOCloseAction extends PMOMultipleBillAction {
    private static final long serialVersionUID = -1274586903782555854L;

    public PMOCloseAction() {
        this.setCode("PMOClose");
        this.setBtnName(PMOConstLang.getBTN_CLOSE_NAME());
        this.putValue("ShortDescription", PMOConstLang.getBTN_CLOSE_SHORT_DESCRIPTION());
    }

    protected boolean isActionEnable() {
        Object[] objects = this.getModel().getSelectedOperaDatas();
        if (MMArrayUtil.isEmpty(objects)) {
            return false;
        } else if (objects.length > 1) {
            return true;
        } else {
            PMOAggVO aggvo = (PMOAggVO)objects[0];
            return PMOFBillstatusEnum.AUDIT.equalsValue(aggvo.getParentVO().getFbillstatus());
        }
    }

    protected ISingleBillService<Object> getSingleBillService() {
        ISingleBillService<Object> service = new ISingleBillService<Object>() {
            public Object operateBill(Object bill) throws Exception {
                PMOAggVO agg = (PMOAggVO)bill;
                PMOAggVO[] bills = null;

                try {
                	NCLocator.getInstance().lookup(IPMOCloseServerIpm.class).pmoClose(new PMOAggVO[]{agg});
                    bills = PMOService.getIPMOBusinessService().close(new PMOAggVO[]{agg});
                   
                } catch (Exception var7) {
                    Throwable exp = ExceptionUtils.unmarsh(var7);
                    if (exp instanceof IResumeException) {
                        if (BusinessCheck.ATPCheck.getCheckCode().equals(((IResumeException)exp).getBusiExceptionType())) {
                            int back = MessageDialog.showYesNoDlg(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), PMOConstLang.getDLG_ATP_TITLE(), ((AtpNotEnoughException)exp).getMessage());
                            if (4 == back) {
                                agg.getParentVO().setFatpcheck("ATPCHECK_OK");
                                bills = PMOService.getIPMOBusinessService().close(new PMOAggVO[]{agg});
                                NCLocator.getInstance().lookup(IPMOCloseServerIpm.class).pmoClose(new PMOAggVO[]{agg});
                            } else {
                                ExceptionUtils.wrappBusinessException(PMOConstLang.getMSG_ATP_NOT_ENOUGH());
                            }
                        }
                    } else {
                        ExceptionUtils.wrappException(var7);
                    }
                }
                
                return MMArrayUtil.isEmpty(bills) ? null : bills[0];
            }
        };
        
        return service;
    }
}
